package cn.echoedu.command;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import cn.echoedu.command.base.ExecuteParam;
import cn.echoedu.command.base.FailureParam;
import cn.echoedu.command.base.SuccessParam;
import cn.echoedu.entity.HomePageImage;

import com.google.gson.Gson;

public class IndexPicQueryCommand extends BaseCommand{



	public void executeSuccess(SuccessParam successparam) {
		// TODO Auto-generated method stub
        List<HomePageImage> homepageimagelist=(List<HomePageImage>)successparam.getParam();
	    IndexPicQuerySuccessResponse indexpicquerysuccess=new IndexPicQuerySuccessResponse();
	    List<IndexPicQueryEntity> indexpicquerylist=
	    		new ArrayList<IndexPicQueryEntity>();
	    for(HomePageImage homepageimage:homepageimagelist){
	    	IndexPicQueryEntity indexpicqueryentity=new IndexPicQueryEntity();
	    	indexpicqueryentity.setPic_id(homepageimage.getImage().getImageid());
	    	indexpicqueryentity.setPic_url(homepageimage.getImage().getImagesrc());
	    	indexpicqueryentity.setImage_to_url(homepageimage.getImagetourl());
	    	indexpicquerylist.add(indexpicqueryentity);
	    }
	    indexpicquerysuccess.setList(indexpicquerylist);
	    Gson g=new Gson();
	    String sendjson=g.toJson(indexpicquerysuccess);
	    send(sendjson,successparam.getResponse());
	}

	public void executeFailure(FailureParam failureparam) {
		// TODO Auto-generated method stub

	}

	public void execute(ExecuteParam executeparam) {
		// TODO Auto-generated method stub
		
	}
	private class IndexPicQuerySuccessResponse{
		private int code=101;
		private String msg="IndexPicQuery Success";
		private List<IndexPicQueryEntity> list;
		public int getCode() {
			return code;
		}
		public void setCode(int code) {
			this.code = code;
		}
		public String getMsg() {
			return msg;
		}
		public void setMsg(String msg) {
			this.msg = msg;
		}
		public List<IndexPicQueryEntity> getList() {
			return list;
		}
		public void setList(List<IndexPicQueryEntity> list) {
			this.list = list;
		}

	}
	private class IndexPicQueryEntity{
		private int pic_id;
		private String pic_url;
		private String image_to_url;
		public int getPic_id() {
			return pic_id;
		}
		public void setPic_id(int pic_id) {
			this.pic_id = pic_id;
		}
		public String getPic_url() {
			return pic_url;
		}
		public void setPic_url(String pic_url) {
			this.pic_url = pic_url;
		}
		public String getImage_to_url() {
			return image_to_url;
		}
		public void setImage_to_url(String image_to_url) {
			this.image_to_url = image_to_url;
		}

	}

}
